﻿using System;
using System.Xml;

namespace MMK.Paket_Tracker.Runtime.Helper
{
    /// <summary>
    /// Class to read the settings from an XML file
    /// </summary>
    /// 
    public static class Setup
    {
        /// <summary>
        /// Reads a single node out of a given XML document.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="nodeName">Name of the node.</param>
        /// <returns></returns>
        public static XmlNode ReadNode(String path, String nodeName)
        {
            XmlNode result;
            XmlNode xmlDoc;
            XmlDocument doc = new XmlDocument();
            try
            {
                if (path.Contains("\\"))
                {
                    doc.Load(path);
                }
                else
                {
                    doc.Load(@path);
                }
                xmlDoc = doc.DocumentElement;
                result = xmlDoc.SelectSingleNode("descendant::" + nodeName);
            }
            catch (Exception)
            {
                result = new XmlDocument();
            }
            return result;
        }
    }
}
